<?php
/**
	Classes:
	zone (myDbTb :: myClass)
	country (myDbTb :: myClass)

	IT manages the address data to make database operations
*/
class zone extends myDbTb{
	public $id;
	public $name;
	public $country_id;

	/*
	 * It loads zone data from DB
	 * It returns 0 if the data has not been loaded.
	 */
	function db_load() {
		$sql = "SELECT z.* FROM " .
			TABLE_ZONES . " z " .
			" where z.id = '".$this->id."'";

		return $this->sql_request($sql);
	}
}
class country extends myDbTb{
	public $id;
	public $name;
	public $zones;

	/*
	 * It loads country data from DB
	 * It returns 0 if the data has not been loaded.
	 */
	function db_load() {
		$sql = "SELECT c.* FROM " .
			TABLE_COUNTRIES . " c " .
			" where c.id = '".$this->id."'";

		return $this->sql_request($sql);
	}

	/*
	 * It loads country zones zone_id from DB
	 * It returns 0 if the data has not been loaded.
	 */
	function db_load_zones() {
		$this->zones=array();
		$sql="SELECT z.* FROM " .
			TABLE_ZONES . " z" .
			" WHERE z.country_id=" . $this->id .
			" ORDER BY z.name asc";
		global $server;
		$result = $server->db->link->query($sql);
		for($i = 0; $i < $result->num_rows; $i++) {
			$zone=new zone();
			$zone->set_from_array($result->fetch_array());
			array_push($this->zones, $zone);
		}
		return ($result->num_rows > 0);
	}
}
?>
